package msu.ml.data;

import msu.ml.data.level2.*;
import java.sql.*;

public class BasicPulseVolumeSQLAdapter implements IPulseVolumeSQLAdapter
{
    int limit;

    public BasicPulseVolumeSQLAdapter(int limit)
    {
        this.limit = limit;
    }

    public int getLimit() { return this.limit; }

    public void setLimit(int limit) {this.limit = limit;}

    public String createQuery(String volumeName)
    {
        String query = "SELECT " + 
        "pulse_volumes.*, " + 
        "sweeps.class " + 
        "FROM volumes, sweeps, pulse_volumes " + 
        "WHERE pulse_volumes.sweep_id = sweeps.sweep_id AND " +
        "sweeps.volume_id = volumes.volume_id AND " + 
        "volumes.ncdc_filename = '" + volumeName + "' ";

        if(limit > 0)
            query += ("LIMIT " + this.limit);

        query += ";";

        return query;
    }

    public IPulseVolume getPulseVolume(ResultSet result)
    {
        try
        {
            DynamicPulseVolume pv = new DynamicPulseVolume();
            pv.addFeature("azimuth", result.getDouble(3));
            pv.addFeature("range", result.getDouble(4));
            pv.addFeature("reflectivity", result.getDouble(5));
            pv.addFeature("velocity", result.getDouble(6));
            pv.addFeature("spectrumwidth", result.getDouble(7));
            pv.addFeature("refvariance", result.getDouble(8));
            pv.addFeature("refkurtosis", result.getDouble(9));
            pv.addFeature("refskewness", result.getDouble(10));
            pv.addFeature("velvariance", result.getDouble(11));
            pv.addFeature("velkurtosis", result.getDouble(12));
            pv.addFeature("velskewness", result.getDouble(13));
            pv.addFeature("specvariance", result.getDouble(14));
            pv.addFeature("speckurtosis", result.getDouble(15));
            pv.addFeature("specskewness", result.getDouble(16));
            pv.addFeature("class", result.getDouble(17));
            return pv;
        }
        catch(Exception e) { }

        return null;
    }
}
